//
//  DFAppDelegate.m
//  DFKit
//
//  Created by chenrj90 on 04/08/2017.
//  Copyright (c) 2017 chenrj90. All rights reserved.
//

#import "DFAppDelegate.h"
#import <DFKit/DFKitShare.h>
#import <DFKit/DFKitAnalyze.h>
#import "DFMainTabBarController.h"

@interface DFAppDelegate()<DFRouterConfig>

@end

@implementation DFAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    //注册分享平台的AppKey
    [DFShareManager registerWithAppKey:@"5861e5daf5ade41326001eab"];
    
    //注册微信分享AppKey
    [DFShareManager setAppKey:@"wxdc1e388c3822c80b" appSecretKey:@"3baf1193c85774b3fd9d18447d76cab0" platform:DFSharePlatformTypeWechatSession redirectURL:nil];
    
    //注册QQ分析AppKey
    [DFShareManager setAppKey:@"1105821097" appSecretKey:nil platform:DFSharePlatformTypeQQ redirectURL:nil];
    
    //注册新浪微博AppKey
    [DFShareManager setAppKey:@"3921700954" appSecretKey:@"04b48b094faeb16683c32669824ebdad" platform:DFSharePlatformTypeSinaWeibo redirectURL:nil];
    
    //启用友盟统计
    [DFAnalyzeManager startAnalyzePlatform:DFAnalyzePlatformUM withAppKey:@"54448737fd98c53d2b0018af" secretKey:@"secretstringaldfkals" channel:@"AppStore"];
    
    //启用DFRouter
    [DFRouter startWithConfig:self];
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.rootViewController = [DFRouter pageWithURL:DF_MAIN withNav:NO];
    [self.window makeKeyAndVisible];
    
    return YES;
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
    BOOL result = [DFShareManager handleOpenURL:url options:options];
    if (!result) {

    }
    [self openURL:url];
    return result;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    BOOL result = [DFShareManager handleOpenURL:url sourceApplication:sourceApplication annotation:sourceApplication];
    if (!result) {
        
    }
    [self openURL:url];
    return result;
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    BOOL result = [DFShareManager handleOpenURL:url];
    if (!result) {

    }
    [self openURL:url];
    return result;
}

#pragma mark - handle open url

- (void)openURL:(NSURL *)url {
    if ([url.scheme isEqualToString:[self schemeName]]) {
        [DFRouter openURL:url.absoluteString];
    }
}

#pragma mark - DFRouterConfig

- (NSString *)schemeName {
    return @"dfkit";
}

- (UITabBarController *)mainTabBarController {
    return (DFMainTabBarController*)self.window.rootViewController;
}

- (UIViewController *)topViewController {
    UIViewController *vc = [[UIApplication sharedApplication].windows[0].rootViewController df_topViewController];
    return vc;
}

@end
